#!/usr/bin/env python
# # -*- coding: utf-8 -*-

from tkinter import *
import sesson2.subject2
import sesson2.subject1
import hashlib
import os
import random
import sys
import os
import ctypes
import time
import time
from threading import Timer
import sesson2
print("path",os.path.dirname(__file__)+"/sesson2/subject2")
import sesson2.subject2.sesson2_2_main as sesson2_2
import sesson2.subject1.session2_1_main as sesson2_1
# sys.path.append(os.path.dirname(__file__))
import os


from multiprocessing import Process

def sesson2_button2_process(arg):
    print("sesson2_button2_fun")
    ret=sesson2_2.sesson2_2_main()
    if (ret == True):
        print("运行成功")
    else:
        print("运行失败")
    print(arg)
def sesson2_button1_process(arg):
    print("sesson2_button1_fun")
    ret=sesson2_1.session2_1_main()
    if (ret == True):
        print("运行成功")
    else:
        print("运行失败")
    print(arg)



class MY_GUI():
    def __init__(self, init_window_name):
        self.init_window_name = init_window_name

    # 设置窗口

    def set_init_window(self):
        self.init_window_name.title("东北大学 参赛队客户端 V1.00")
        # 290 160为窗口大小，+10 +10 定义窗口弹出时的默认展示位置
        # self.init_window_name.geometry('1920x1080+0+0')
        self.init_window_name.geometry('1520x780+100+100')
        # self.init_window_name["bg"] = "pink"                                    #窗口背景色，其他背景色见：blog.csdn.net/chl0000/article/details/7657887
        # self.init_window_name.attributes("-alpha",0.9)                          #虚化，值越小虚化程度越高
        # 标签
        self.sesson1_RV = IntVar()
        self.sesson1_RV.set(3)
        self.init_data_label = Label(self.init_window_name, text="东北大学 参赛队客户端 V1.00",  font=(
            'Arial', 32), width=25, height=2)
        self.init_data_label.grid(row=4, column=1)
        self.init_data_label2 = Label(
            self.init_window_name, text="科目一：",  font=('Arial', 32), width=15, height=2)
        self.init_data_label2.grid(row=5, column=0)

        self.init_data_Radiobutton = Radiobutton(
            self.init_window_name, text="情景一", variable=self.sesson1_RV, value=0,  font=('Arial', 32))
        self.init_data_Radiobutton.grid(row=5, column=1)
        self.init_data_Radiobutton2 = Radiobutton(
            self.init_window_name, text="情景二", variable=self.sesson1_RV, value=1, font=('Arial', 32))
        self.init_data_Radiobutton2.grid(row=5, column=2)
        self.pr_button1 = Button(
            self.init_window_name, text="准备", bg="lightblue", width=10, command=self.sesson1_button1_fun, font=('Arial', 32))  # 调用内部方法  加()为直接调用
        self.pr_button1.grid(row=6, column=1)
        self.submit_button1 = Button(
            self.init_window_name, text="提交答案", bg="lightblue", width=10, command=self.sesson1_button2_fun, font=('Arial', 32))  # 调用内部方法  加()为直接调用
        self.submit_button1.grid(row=6, column=2)

        self.sesson2_label = Label(
            self.init_window_name, text="科目二：",  font=('Arial', 32), width=15, height=2)
        self.sesson2_label.grid(row=7, column=0)
        self.sesson2_Radiobutton1 = Radiobutton(
            self.init_window_name, text="情景一", variable=self.sesson1_RV, value=2,  font=('Arial', 32))
        self.sesson2_Radiobutton1.grid(row=7, column=1)
        self.sesson2_Radiobutton2 = Radiobutton(
            self.init_window_name, text="情景二", variable=self.sesson1_RV, value=3, font=('Arial', 32))
        self.sesson2_Radiobutton2.grid(row=7, column=2)
        self.sesson2_button1 = Button(
            self.init_window_name, text="准备", bg="lightblue", width=10, command=self.sesson2_button1_fun, font=('Arial', 32))  # 调用内部方法  加()为直接调用
        self.sesson2_button1.grid(row=8, column=1)
        self.sesson2_button2 = Button(
            self.init_window_name, text="提交答案", bg="lightblue", width=10, command=self.sesson2_button2_fun, font=('Arial', 32))  # 调用内部方法  加()为直接调用
        self.sesson2_button2.grid(row=8, column=2)

        self.sesson2_label = Label(
            self.init_window_name, text="科目三：",  font=('Arial', 32), width=15, height=2)
        self.sesson2_label.grid(row=9, column=0)
        self.sesson3_Radiobutton1 = Radiobutton(
            self.init_window_name, text="情景一", variable=self.sesson1_RV, value=4,  font=('Arial', 32))
        self.sesson3_Radiobutton1.grid(row=9, column=1)
        self.sesson3_Radiobutton2 = Radiobutton(
            self.init_window_name, text="情景二", variable=self.sesson1_RV, value=5, font=('Arial', 32))
        self.sesson3_Radiobutton2.grid(row=9, column=2)
        self.sesson3_button1 = Button(
            self.init_window_name, text="准备", bg="lightblue", width=10, command=self.sesson3_button1_fun, font=('Arial', 32))  # 调用内部方法  加()为直接调用
        self.sesson3_button1.grid(row=10, column=1)
        self.sesson3_button2 = Button(
            self.init_window_name, text="提交答案", bg="lightblue", width=10, command=self.sesson3_button2_fun, font=('Arial', 32))  # 调用内部方法  加()为直接调用
        self.sesson3_button2.grid(row=10, column=2)

        self.time_text = StringVar()
        self.time_text.set(self.get_current_time())
        self.time_lable = Label(self.init_window_name, textvariable=self.time_text,  font=(
            'Arial', 24), width=24, height=4).grid(row=12, column=2)

        self.t = Timer(1, self.show_time)
        self.t.start()

    # 功能函数


    def sesson3_button1_fun(self):
        print("sesson3_button1_fun")

    def sesson3_button2_fun(self):
        print("sesson3_button2_fun")

    def sesson2_button1_fun(self):

        arg = "sesson2_button1_fun"
        proc = Process(target=sesson2_button1_process, args=(arg,))
        proc.start()
        proc.join()

    def sesson2_button2_fun(self):
        arg = "sesson2_button2_fun"
        proc = Process(target=sesson2_button2_process, args=(arg,))
        proc.start()
        proc.join()
 
    def sesson1_button1_fun(self):


        # t1 = thread1()
        # t1.start()
        test_dll=ctypes.cdll.LoadLibrary('C:\\Users\\tang\\Desktop\\RHZT\R1\\jsontest3\\x64\\Release\\jsontest.dll')
        vvvv=test_dll.cpp_sum(3,5)
        print(vvvv)
        # print("sesson1_button1_fun")

    def sesson1_button2_fun(self):
        print("sesson1_button2_fun")
    def print_time( threadName, delay):
        count = 0
        while count < 5:
            time.sleep(delay)
            count += 1
            print ("%s: %s" % ( threadName, time.ctime(time.time()) ))
    # 获取当前时间
    def show_time(self):
        self.time_text.set(self.get_current_time())
        self.t.cancel()
        self.t = Timer(1, self.show_time)
        self.t.start()

    def get_current_time(self):
        current_time = time.strftime(
            '%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
        return current_time


def gui_start():
    init_window = Tk()  # 实例化出一个父窗口
    ZMJ_PORTAL = MY_GUI(init_window)
    # 设置根窗口默认属性
    ZMJ_PORTAL.set_init_window()
    init_window.mainloop()  # 父窗口进入事件循环，可以理解为保持窗口运行，否则界面不展示

if __name__ == '__main__':
    gui_start()

